#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=200;
typedef long long LL;
LL a[maxn][maxn],b[maxn][maxn],c[maxn][maxn];
LL n,m;
bool check1(){
    for(LL i=1;i<=n;i++){
        for(LL j=1;j<=m;j++){
            if(a[i][j]==a[i][j-1]||a[i][j]==a[i+1][j]||a[i][j]==a[i][j+1]||a[i][j]==a[i-1][j]){
                return false;
            }
        }
    }
    return true;
}
bool check2(){
    for(LL i=1;i<=n;i++){
        for(LL j=1;j<=m;j++){
            if(b[i][j]==b[i][j-1]||b[i][j]==b[i+1][j]||b[i][j]==b[i][j+1]||b[i][j]==b[i-1][j]){
                return false;
            }
        }
    }
    return true;
}
bool check3(){
    for(LL i=1;i<=n;i++){
        for(LL j=1;j<=m;j++){
            if(c[i][j]==c[i][j-1]||c[i][j]==c[i+1][j]||c[i][j]==c[i][j+1]||c[i][j]==c[i-1][j]){
                return false;
            }
        }
    }
    return true;
}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL t;cin>>t;
  while(t--){
    memset(a,0,sizeof(a));memset(b,0,sizeof(b));memset(c,0,sizeof(c));
    cout<<endl;
    cin>>n>>m;
    for(LL i=1;i<=n;i++){
        for(LL j=1;j<=m;j++){
            cin>>a[i][j];b[i][j]=c[i][j]=a[i][j];
        }
    }
    for(LL i=1;i<=n;i++){
        for(LL j=1;j<=m;j++){
            if(b[i][j]==b[i][j-1]||b[i][j]==b[i+1][j]||b[i][j]==b[i][j+1]||b[i][j]==b[i-1][j]){
                if( ( i+j )%2==0){
                    b[i][j]++;
                }
            }
        }
    }
    for(LL i=1;i<=n;i++){
        for(LL j=1;j<=m;j++){
            if(c[i][j]==c[i][j-1]||c[i][j]==c[i+1][j]||c[i][j]==c[i][j+1]||c[i][j]==c[i-1][j]){
                if( ( i+j )%2==1){
                    c[i][j]++;
                }
            }
        }
    }
    LL shuchu=0;
    if(check1()==true){
        shuchu=1;
    }
    if(check2()==true){
        shuchu=2;
    }
    if(check3()==true){
        shuchu=3;
    }
    cout<<endl;
    if(shuchu==1){
        for(LL i=1;i<=n;i++){
            for(LL j=1;j<=m;j++){cout<<a[i][j]<<" ";}
            cout<<endl;
        }
    }
    else if(shuchu==2){
        for(LL i=1;i<=n;i++){
            for(LL j=1;j<=m;j++){cout<<b[i][j]<<" ";}
            cout<<endl;
        }
    }
    else if(shuchu==3){
        for(LL i=1;i<=n;i++){
            for(LL j=1;j<=m;j++){cout<<c[i][j]<<" ";}
            cout<<endl;
        }
    }
  }
return 0;
}
